<?php
include "exchange.class.php";
/**
 * Class ExchangeList
 *
 *
 * @name exchangeList.class.php
 * @author
 * @copyright
 * @version

 */


Class ExchangeList {


	/**
	 *	Méthodes de la classe
	 */

	public function __construct(){
	}

	// Retourne un Array de tous les exchanges
	public function getList() {
		$sql = Bdd::getInstance();
		$return =  Array();
		$results = $sql->query("SELECT * FROM `Exchange`");
		
		foreach($results as $oneResult){
			$theResult = new Exchange();  // CrŽe une instance Exchange
			$theResult->initialisation(
									$oneResult["idExchange"],
									$oneResult["\$idPerson1"],
									$oneResult["\$idPerson2"],
									$oneResult["date"],
									$oneResult["\$idObjectPerson1"],
									$oneResult["\$idObjectPerson2"],
									$oneResult["stateExchange1"],
									$oneResult["stateExchange2"]
									);
			 
			$return[$oneResult["idExchange"]] = $theResult;  // Ajoute l'objet Exchange dans le Array()
		}
		return $return; // Retourne l'Array()

	}

	// Retourne une Exchange selon l'ID passer en param�tre
	public function getExchange($p_idExchange) {
		$sql = Bdd::getInstance();
		$result = $sql->query("SELECT * FROM `Exchange` WHERE idExchange = $p_idExchange");
		$result = $result->fetch();
 
		$return = new Exchange();  // Crée une instance Exchange
		$return->initialisation(
									$result["idExchange"],
									$result["\$idPerson1"],
									$result["\$idPerson2"],
									$result["date"],
									$result["\$idObjectPerson1"],
									$result["\$idObjectPerson2"],
									$result["stateExchange1"],
									$result["stateExchange2"]
								);					
		return $return; // Retourne l'Exchange 
	}
};
?>